//
//  articleTableViewController.m
//  iNews
//
//  Created by lanou3g on 14-12-12.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "articleTableViewController.h"
#import "ArchiveHandleSingle.h"

#import "DetailModel.h"

#import "DetailViewController.h"
#import "DetailWebView.h"

@interface articleTableViewController () <UITableViewDataSource,UITableViewDelegate>


@end

@implementation articleTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detaloadUI) name:@"articleArray" object:nil];
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
   //注册cell
    
   // [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_id"];
   
//    self.tableView.delegate = self;
//    self.tableView.dataSource = self;
}

//观察者方法
- (void)detaloadUI
{
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    
    if ([ArchiveHandleSingle archiveSingle].articleArray.count == 0) {
        return 1;
    }else{
        
        NSLog(@"%@",[ArchiveHandleSingle archiveSingle].articleArray);
        return [ArchiveHandleSingle archiveSingle].articleArray.count;
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *s = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:s];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:s];
    }
    
    if ([ArchiveHandleSingle archiveSingle].articleArray.count == 0) {
        cell.textLabel.text = @"暂无收藏";
        
    }else{
        
        DetailModel *m = [ArchiveHandleSingle archiveSingle].articleArray[indexPath.row];
        
        cell.textLabel.text = m.title;
    }
    
   
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //点击进去收藏的内容页面,不需要联网
    
    NSLog(@"点击了");
    DetailViewController *detailVC = [[DetailViewController alloc] init];
    
    DetailModel *model = [ArchiveHandleSingle archiveSingle].articleArray[indexPath.row];
    
    [detailVC.webV getThml:model];
    
    
    [self.parentViewController.navigationController pushViewController:detailVC animated:YES];
    
}






////编辑样式
//-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//
//  
//
//
//}
////完成编辑
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//
//    if (editingStyle == UITableViewCellEditingStyleDelete) {
//        
//    }else{
//    
//    
//    
//    }
//    
//    
//
//}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
